//设计器，全局对象
window.Design = {
	stageW: 600,
	stageH: 600,
	node: $("#svgView"),
	paper: Snap("#svgView"),
};
Design.utils = require("./utils/common.js"); //通用工具
Design.mainEditer = require("./mainEditer.js"); //编辑舞台
Design.event = new require("./dhc/eventDHC.js"); //事件管理器
Design.tool = require("./tf/myTransformTool.js"); //变形工具
Design.view = require("./view/view.js"); //视图

/*
 * 初始化界面
 */
Design.init = function(data) {
	this.tool.init();
	this.view.init();
	this.mainEditer.init();
	
	/*
	 * 事件监听
	 */
	this.event.on(this.event.UPDATE_DEDSIGN_DATA, eventHandler);
	this.event.on(this.event.ADD_PRODUCT, eventHandler);
	this.event.on(this.event.ADD_ELEMENT, eventHandler);
	this.event.on(this.event.DEL_ELEMENT, eventHandler);
	this.event.on(this.event.ICON_UPDATE, eventHandler);

	if(data) {
		Design.mainEditer.setJson(data);
	}
	layer.closeAll();
	
	// if(config_gl.apiPath.indexOf("http://127.0.0.1:8086/api") != -1){
	// 	layer.alert = function(){
	// 		
	// 	}
	// }
}

/*
 * 事件处理
 */
function eventHandler(eventType, event) {
	var me = Design.mainEditer;
	var ev = Design.event;
	switch(eventType) {
		case ev.UPDATE_DEDSIGN_DATA:
			me.setJson(event);
			break;
		case ev.ADD_PRODUCT:
			me.addProduct(event);
			break;
		case ev.ADD_ELEMENT:
			me.addElement(event);
			break;
		case ev.DEL_ELEMENT:
			me.removeElement(event);
			break;
		case ev.ICON_UPDATE:
			Design.view.updateLayer(event);
			break;
		default:
			break;
	}
}
